package BinaryTree;
/*
* 把二叉搜索树转换为累加树
*
* 逆中序, 遍历结果为从大到小排列
*
* */
public class ConvertBST538 {
    int sum=0;
    public TreeNode convertBST(TreeNode root) {
        sum(root);
        return root;
    }

    private void sum(TreeNode root) {
        if(root==null)return;
        sum(root.right);
        sum+=root.val;
        root.val=sum;
        sum(root.left);
        return;
    }
}
